import enum
from datetime import datetime

from flask_sqlalchemy import SQLAlchemy
from conf import mysql_host, mysql_user, mysql_password, mysql_db, mysql_port

db = SQLAlchemy()
# mysql config(s)
dbServer = mysql_host
dbCharset = 'utf8'
dbPort = mysql_port
dbName = mysql_db
dbUser = mysql_user
dbPassword = mysql_password


class UserRole(enum.Enum):
    ADMIN = 'ADMIN'
    USER = 'USER'


class Gender(enum.Enum):
    FEMALE = 'F'
    MALE = 'M'


class User(db.Model):
    query: db.Query = db.session.query_property()
    __tablename__ = 't_user'
    __table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'}  # 设置引擎、字符集
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(10), unique=True)
    password = db.Column(db.Text)
    token = db.Column(db.Text)
    fcm_token = db.Column(db.Text)
    role = db.Column(db.Enum(UserRole))


# 定义数据库模型
class Recommendation(db.Model):
    __tablename__ = 't_recommend'
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.String(50), nullable=False)
    destination = db.Column(db.String(50), nullable=False)
    recommendation_data = db.Column(db.JSON, nullable=False)
    created_at = db.Column(db.DateTime, default=datetime.utcnow)


class ScenicSpot(db.Model):
    __tablename__ = 't_scenic-spot'
    id = db.Column(db.Integer, primary_key=True)
    image_url = db.Column(db.String(255))  # 存储图片的 URL
    text = db.Column(db.Text)  # 存储相关的文字
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    # 其他可能的字段，例如创建时间、作者等


class Caregiver(db.Model):
    __tablename__ = 't_caregiver'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255))  # Caregiver's Name
    contact_info = db.Column(db.String(255))  # Contact Information
    experience = db.Column(db.Text)  # Work Experience Description
    joined_at = db.Column(db.DateTime, default=datetime.utcnow)  # Date Joined
    # Other fields as necessary


class ElderlyPersonProfile(db.Model):
    __tablename__ = 't_elderly_person_profile'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255))  # Elderly Person's Name
    age = db.Column(db.Integer)  # Age
    health_info = db.Column(db.Text)  # Health Information
    admission_date = db.Column(db.DateTime, default=datetime.utcnow)  # Admission Date
    # Other fields as necessary, like emergency contact, room number, etc.


class Tag(db.Model):
    __tablename__ = 't_tag'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), unique=True, nullable=False)


class NursingNews(db.Model):
    __tablename__ = 'nursing_news'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(255), nullable=False)
    image_url = db.Column(db.String(255))  # 存储图片的 URL
    content = db.Column(db.Text, nullable=False)
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    # Add other relevant fields as needed


# connect mysql
def connect():
    return f'mysql+pymysql://{dbUser}:{dbPassword}@{dbServer}:{dbPort}/{dbName}?charset={dbCharset}'
